<script type="text/javascript">
    function jqxFixColumns(columns){
        try{
            columns['Type'].createeditor=function (row, cellvalue, editor) {
                editor.jqxNumberInput({ decimalDigits: 0 });
            };
            columns['Name'].validation= function (cell, value) {
                if (value =="") {
                    return { result: false, message: "Name should be non-empty." };
                }
                return true;
            };
        }catch(e){tipMessage(e.message);}
        return columns;
    }
    function handleEvent_jqxGrid(jqxgrid){
        jqxgrid.bind('cellendedit', function (event) {
            try{
                var args = event.args;
                var Column = args.datafield ,Row = args.rowindex,Value = args.value;
                var Data=jqxgrid.jqxGrid('getrowdata', Row);
                var ID=Data.ID;
                if(ID==undefined || ID==""){
                    return;
                }
                switch(Column){
                    case "Status":
                        updateCol("status",ID,Value);
                        break;
                    case "Type":
                        if(Data.Type!=Value){
                            updateCol("Type",ID,Value);
                        }
                        break;
                    case "Value":
                        if(Data.Keyword!=Value){
                            updateCol("Value",ID,Value);
                        }
                        break;
                    case "Name":
                        if(Data.Name!=Value){
                            updateCol("Name",ID,Value);
                        }
                        break;
                    default:
                    tipMessage("Unkown this cell. Maybe 'editable' of this colums is 'off'"); 
                }
            }catch(e){
                tipMessage(e.message);
                console.log("Error:"+e.message);
            }
        });
    }
    function SaveItem(){
        try{
            if(isrunning)return;
            console.log("Save ↵ Call");
                                          
            var url="{{base_url()}}APanel/{{$controller}}/Save";
            var data={
                ID              :   $('#txtID').val(),
                Name            :   $('#txtName').val(),
                Value           :   $('#txtValue').val(),
                Type            :   $('#txtType').val()
            }
            //ShowNoticeDialogMessage($("<div />").text(Content).html());return;
            console.log(data);
            isrunning=true;
            jqxAjax(url,data,function(result){
                isrunning=false;
                if(result.code>=0){
                    myjqxGrid.CancelEdit();
                    myjqxGrid.Refresh();
                }else{
                    tipMessage(result.msg);
                }
            });
        }catch(e){
            console.log("JSON Error:"+e.message+"\n↵ Error");
            tipMessage(e.message);
            //ShowErrorDialogMessage("Sorry. Your request could not be completed.<br/> Please check your input data.");
        }
    }
</script>